using Identity.Application.Contracts.Responses.Account;
using Identity.Application.Contracts.Services;
using Identity.Application.Users.Commands;
using MediatR;

namespace Identity.Application.Users.CommandHandler;

public class GetConfirmEmailTokenCommandHandler : IRequestHandler<GetConfirmEmailTokenCommand, ConfirmEmailDto>
{
    private readonly IUserService _userService;

    public GetConfirmEmailTokenCommandHandler(IUserService userService)
    {
        _userService = userService;
        
    }
    public async Task<ConfirmEmailDto> Handle(GetConfirmEmailTokenCommand request, CancellationToken cancellationToken)
    {
        var token = await _userService.GenerateEmailConfirmationTokenAsync(request.userId);
        return new ConfirmEmailDto(request.userId, token);

    }
}